<template>
	<view class="boxs">
		<view class="" @click="changes" v-if="adst==1">
			<image src="https://h5.sx2b2c.com/images/common/float-ad-icon.gif" mode="" class="adbox"></image>
		</view>
		<image src="https://web.78keji.cn/images/etc/backv.png" style="width: 100%;" class="backv"></image>
		<view class="box" style="position: relative;">
			<view class=""
				style="color: #084CF5;font-size: 42rpx;position: absolute;text-align: center;width: 100%;top: 60rpx;">
				绑定车牌号马上免费领取
			</view>
			<view class="" style="width: 100%;padding-left: 40rpx;padding-right: 40rpx;">
				<image src="https://web.78keji.cn/images/etc/gifs.gif" mode="widthFix"
					style="z-index: 999;width: 100%;"></image>
			</view>
			<view class="" style="padding: 0 20rpx;" @tap="changex">
				<image src="https://web.78keji.cn/images/etc/btn.png" mode="widthFix"
					style="margin-top: 10rpx;width: 100%;"></image>
			</view>

		</view>
	</view>

</template>

<script>
			import FingerprintJS from '@fingerprintjs/fingerprintjs' // 引入
	import {
		getip,
		getUrl,
		subOrder,
		mobileQuery,
		alipayadsta,
		logs
	} from "../../api/index.js"
	export default {
		data() {
			return {
				deviceid:'',
				a: '',
				param: "",
				mobile: '',
				orderNo: "", //订单号
				adst: 0, //信封显示与否
				url: "",
			};
		},
		onShow() {
			//每次进入页面刷新记录
		this.getvisitorId()
		},
		onLoad(option) {

			if (option.urlCode) {
				this.param = option.urlCode
				uni.setStorageSync('param', option.urlCode)
			}

			if (option.tokenId) {
				this.param = option.tokenId
				uni.setStorageSync('param', option.tokenId)
			}
			if (option.clickid) {
				uni.setStorageSync('param', option.clickid)
				this.param = option.clickid
			}
			if (option.a_oId) {
				uni.setStorageSync('param', option.a_oId)
				this.param = option.a_oId
			}
			if (option.a_oid) {
				uni.setStorageSync('param', option.a_oid)
				this.param = option.a_oid
			}
			if (option.param) {
				uni.setStorageSync('param', option.param)
				this.param = option.param
			}
			console.log(this.param)
			if (option.a) {
				uni.setStorageSync('a', option.a)
				this.a = option.a
				const formDatax = new FormData();

				formDatax.append('a', uni.getStorageSync('a'));
				fetch('https://www.sx2b2c.com/api/dhk3000/getAdUrl', {
						method: 'post',
						body: formDatax
					})
					.then(response => response.json())
					.then(data => {
						console.log(data)
						this.adst = data.data.adst
						this.url = data.data.url1 //信封跳转地址


					})
					.catch(error => console.error(error));

			}
		},
		methods: {
			async getvisitorId() {
				const fp = await FingerprintJS.load()
				const result = await fp.get()
				this.deviceid = result.visitorId
				logs({
					a: this.a,
					eventType: 1,
					xcx: 3,
					deviceid: this.deviceid
				}).then((res) => {
					console.log(res)
					
				})
				console.log(this.deviceid)
			},
			getRandomNum() {
				var a = new Date().getFullYear() + (new Date().getMonth() + 1).toString().padStart(2, "0") +
					new Date().getDate().toString().padStart(2, "0")
				//  "2020-02-12"   获取的是当前日期
				var b = new Date().getHours().toString().padStart(2, "0") + new Date().getMinutes().toString()
					.padStart(2, "0") + new Date().getSeconds().toString().padStart(2, "0")
				//11:13:02当前时间
				var randomNum = "" + Math.round(Math.random() * 900000000);
				while (randomNum.length < 8) {
					randomNum = "0" + randomNum;
				}
				const number = 'AD' + a + b + randomNum
				this.orderNo = number


				return randomNum;
			},
			changes() {
				// 在这里编写处理点击事件的逻辑
				window.location.href = this.url
			},
			changex() {
				logs({
					a: this.a,
					eventType: 2,
					xcx: 3,
					deviceid: this.deviceid
				}).then((res) => {
					console.log(res)
				})
				this.getRandomNum()
				if (/MicroMessenger/.test(window.navigator.userAgent)) {
					let system = navigator.userAgent.toLowerCase();
					//微信环境==苹果跳转支付宝
					if (/(iPhone|iPad|iPod|iOS)/i.test(system)) {
						subOrder({
							a: this.a,
							param: this.param,
							mobile: this.mobile,
							nomobile: '1',
							from_t: '1',
							from_env: '2',
							orderNo: this.orderNo
						}).then((res) => {
							window.location.href = `https://ulink.alipay.com/?scheme=` +
								encodeURIComponent(
									`alipays://platformapi/startapp?appId=2021004129621025&page=pages/etcs/etcs&query=${encodeURIComponent('mobile='+this.mobile+'&a='+this.a +'&param='+this.param+'&orderNo='+this.orderNo+'&deviceid='+this.deviceid    )}`
								)
						})

						// wx.navigateToMiniProgram({ appId: '2021004115620105'})
						// extraData: { // 可选，传递给支付宝小程序的额外数据 }, success(res) { // 跳转成功的回调函数 }, fail(res) { // 跳转失败的回调函数 } })
					} else {
						subOrder({
							a: this.a,
							param: this.param,
							mobile: this.mobile,
							nomobile: '1',
							from_t: '2',
							from_env: '2',
							orderNo: this.orderNo
						}).then((res) => {
							uni.navigateTo({
								url: "/pages/etclead/etclead?mobile=" + this.mobile + '&a=' +
									this.a + '&param=' + this.param + '&orderNo=' + this
									.orderNo+'&deviceid='+this.deviceid 
							})
						})


					}

				} else if (/AlipayClient/.test(window.navigator.userAgent)) {

					subOrder({
						a: this.a,
						param: this.param,
						mobile: this.mobile,
						nomobile: '1',
						from_t: '0',
						from_env: '1',
						orderNo: this.orderNo
					}).then((res) => {
						//支付宝环境
						window.location.href = `https://ulink.alipay.com/?scheme=` +
							encodeURIComponent(
								`alipays://platformapi/startapp?appId=2021004129621025&page=pages/etcs/etcs&query=${encodeURIComponent('mobile='+this.mobile+'&a='+this.a +'&param='+this.param+'&orderNo='+this.orderNo+'&deviceid='+this.deviceid    )}`
							)
					})
				} else {
					// 其他环境
					subOrder({
						a: this.a,
						param: this.param,
						mobile: this.mobile,
						nomobile: '2',
						from_t: '0',
						from_env: '0',
						orderNo: this.orderNo
					}).then((res) => {
						console.log(res)
						window.location.href = `https://ulink.alipay.com/?scheme=` +
							encodeURIComponent(
								`alipays://platformapi/startapp?appId=2021004129621025&page=pages/etcs/etcs&query=${encodeURIComponent('mobile='+this.mobile+'&a='+this.a +'&param='+this.param+'&orderNo='+this.orderNo+'&deviceid='+this.deviceid   )}`
							)
					})
				}
			}
		}
	}
</script>

<style>
	.boxs {
		position: relative;
		height: 100%;
	}

	.box {
		width: 100%;
		text-align: center;

		background: #FFFFFF;
		height: 340rpx;
		border-radius: 28rpx 28rpx 0rpx 0rpx;
		z-index: 2;

		padding-top: 40rpx;
	}

	.adbox {
		position: fixed;
		bottom: 25%;
		right: 0;
		width: 100rpx;
		height: 100rpx;
		z-index: 9999;
	}

	.backv {
		height: calc(100% - 350rpx) !important;
		background-size: 100% 100%;
	}
</style>